package com.zxn.japp;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;

import butterknife.ButterKnife;
import butterknife.OnClick;

@Route(path = IARouterConfig.HOME_MAIN_ACTIVITY_URL)
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        ARouter.getInstance().inject(this);
    }

    @OnClick({R.id.btn_jump,
            R.id.btn_jump2,
            R.id.btn_jump3,
            R.id.btn_jump4,
    })
    public void onViewClicked(View view) {
        int viewId = view.getId();
        if (viewId == R.id.btn_jump) {
            ARouter.getInstance().build(IARouterConfig.HOME_SIMPLE_ACTIVITY_URL).navigation();
        } else if (viewId == R.id.btn_jump2) {
            //ARouter.getInstance().build(IARouterConfig.HOME_MENU_ACTIVITY_URL).navigation();
            ARouter.getInstance().build(IARouterConfig.HOME_MENU_ACTIVITY_URL)
                    .withBoolean("loginResult", true)
                    .withDouble("amount", 20000.5)
                    .withString("name", "张超")
                    .withInt("age", 28)
                    .navigation();
        }else if (viewId == R.id.btn_jump3) {
            ARouter.getInstance().build(IARouterConfig.HOME_TAB_ACTIVITY_URL).navigation();
        }else if (viewId == R.id.btn_jump4) {
            int requestCode = 100;
            ARouter.getInstance()
                    .build(IARouterConfig.HOME_RESULT_ACTIVITY_URL)
                    .navigation(this,requestCode);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 100:
                if (resultCode == 200) {
                    Toast.makeText(this, "收到回调了", Toast.LENGTH_LONG).show();
                }
                break;
        }
    }

}
